/**
 */
package org.mro.grib.model.files.firstEdition.sections.impl;

import java.nio.ByteBuffer;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.mro.grib.core.Grib1Constantes;
import org.mro.grib.model.files.firstEdition.sections.BinaryDataSection;
import org.mro.grib.model.files.firstEdition.sections.SectionsPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Binary Data Section</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BinaryDataSectionImpl#getStartOffset <em>Start Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BinaryDataSectionImpl#getEndOffset <em>End Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BinaryDataSectionImpl#getLength <em>Length</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BinaryDataSectionImpl#getNumberOfUnusedBitsAtEndOfSection4 <em>Number Of Unused Bits At End Of Section4</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BinaryDataSectionImpl#getBinaryScaleFactorE <em>Binary Scale Factor E</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BinaryDataSectionImpl#getReferenceValue <em>Reference Value</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BinaryDataSectionImpl#getSizeOfPackedDatum <em>Size Of Packed Datum</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BinaryDataSectionImpl#getDataOffset <em>Data Offset</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BinaryDataSectionImpl extends EObjectImpl implements BinaryDataSection {
	/**
	 * The default value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long START_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected long startOffset = START_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long END_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected long endOffset = END_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected static final int LENGTH_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected int length = LENGTH_EDEFAULT;

	/**
	 * The default value of the '{@link #getNumberOfUnusedBitsAtEndOfSection4() <em>Number Of Unused Bits At End Of Section4</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNumberOfUnusedBitsAtEndOfSection4()
	 * @generated
	 * @ordered
	 */
	protected static final byte NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getNumberOfUnusedBitsAtEndOfSection4() <em>Number Of Unused Bits At End Of Section4</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNumberOfUnusedBitsAtEndOfSection4()
	 * @generated
	 * @ordered
	 */
	protected byte numberOfUnusedBitsAtEndOfSection4 = NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4_EDEFAULT;

	/**
	 * The default value of the '{@link #getBinaryScaleFactorE() <em>Binary Scale Factor E</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBinaryScaleFactorE()
	 * @generated
	 * @ordered
	 */
	protected static final short BINARY_SCALE_FACTOR_E_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getBinaryScaleFactorE() <em>Binary Scale Factor E</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBinaryScaleFactorE()
	 * @generated
	 * @ordered
	 */
	protected short binaryScaleFactorE = BINARY_SCALE_FACTOR_E_EDEFAULT;

	/**
	 * The default value of the '{@link #getReferenceValue() <em>Reference Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReferenceValue()
	 * @generated
	 * @ordered
	 */
	protected static final int REFERENCE_VALUE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getReferenceValue() <em>Reference Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReferenceValue()
	 * @generated
	 * @ordered
	 */
	protected int referenceValue = REFERENCE_VALUE_EDEFAULT;

	/**
	 * The default value of the '{@link #getSizeOfPackedDatum() <em>Size Of Packed Datum</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSizeOfPackedDatum()
	 * @generated
	 * @ordered
	 */
	protected static final byte SIZE_OF_PACKED_DATUM_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getSizeOfPackedDatum() <em>Size Of Packed Datum</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSizeOfPackedDatum()
	 * @generated
	 * @ordered
	 */
	protected byte sizeOfPackedDatum = SIZE_OF_PACKED_DATUM_EDEFAULT;

	/**
	 * The default value of the '{@link #getDataOffset() <em>Data Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long DATA_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getDataOffset() <em>Data Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataOffset()
	 * @generated
	 * @ordered
	 */
	protected long dataOffset = DATA_OFFSET_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BinaryDataSectionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SectionsPackage.Literals.BINARY_DATA_SECTION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getStartOffset() {
		return startOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartOffset(long newStartOffset) {
		long oldStartOffset = startOffset;
		startOffset = newStartOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BINARY_DATA_SECTION__START_OFFSET, oldStartOffset, startOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getEndOffset() {
		return endOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEndOffset(long newEndOffset) {
		long oldEndOffset = endOffset;
		endOffset = newEndOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BINARY_DATA_SECTION__END_OFFSET, oldEndOffset, endOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getLength() {
		return length;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLength(int newLength) {
		int oldLength = length;
		length = newLength;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BINARY_DATA_SECTION__LENGTH, oldLength, length));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getNumberOfUnusedBitsAtEndOfSection4() {
		return numberOfUnusedBitsAtEndOfSection4;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setNumberOfUnusedBitsAtEndOfSection4(byte newNumberOfUnusedBitsAtEndOfSection4) {
		byte oldNumberOfUnusedBitsAtEndOfSection4 = numberOfUnusedBitsAtEndOfSection4;
		numberOfUnusedBitsAtEndOfSection4 = newNumberOfUnusedBitsAtEndOfSection4;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BINARY_DATA_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4, oldNumberOfUnusedBitsAtEndOfSection4, numberOfUnusedBitsAtEndOfSection4));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public short getBinaryScaleFactorE() {
		return binaryScaleFactorE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBinaryScaleFactorE(short newBinaryScaleFactorE) {
		short oldBinaryScaleFactorE = binaryScaleFactorE;
		binaryScaleFactorE = newBinaryScaleFactorE;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BINARY_DATA_SECTION__BINARY_SCALE_FACTOR_E, oldBinaryScaleFactorE, binaryScaleFactorE));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getReferenceValue() {
		return referenceValue;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setReferenceValue(int newReferenceValue) {
		int oldReferenceValue = referenceValue;
		referenceValue = newReferenceValue;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BINARY_DATA_SECTION__REFERENCE_VALUE, oldReferenceValue, referenceValue));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getSizeOfPackedDatum() {
		return sizeOfPackedDatum;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSizeOfPackedDatum(byte newSizeOfPackedDatum) {
		byte oldSizeOfPackedDatum = sizeOfPackedDatum;
		sizeOfPackedDatum = newSizeOfPackedDatum;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BINARY_DATA_SECTION__SIZE_OF_PACKED_DATUM, oldSizeOfPackedDatum, sizeOfPackedDatum));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getDataOffset() {
		return dataOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDataOffset(long newDataOffset) {
		long oldDataOffset = dataOffset;
		dataOffset = newDataOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BINARY_DATA_SECTION__DATA_OFFSET, oldDataOffset, dataOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SectionsPackage.BINARY_DATA_SECTION__START_OFFSET:
				return getStartOffset();
			case SectionsPackage.BINARY_DATA_SECTION__END_OFFSET:
				return getEndOffset();
			case SectionsPackage.BINARY_DATA_SECTION__LENGTH:
				return getLength();
			case SectionsPackage.BINARY_DATA_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4:
				return getNumberOfUnusedBitsAtEndOfSection4();
			case SectionsPackage.BINARY_DATA_SECTION__BINARY_SCALE_FACTOR_E:
				return getBinaryScaleFactorE();
			case SectionsPackage.BINARY_DATA_SECTION__REFERENCE_VALUE:
				return getReferenceValue();
			case SectionsPackage.BINARY_DATA_SECTION__SIZE_OF_PACKED_DATUM:
				return getSizeOfPackedDatum();
			case SectionsPackage.BINARY_DATA_SECTION__DATA_OFFSET:
				return getDataOffset();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SectionsPackage.BINARY_DATA_SECTION__START_OFFSET:
				setStartOffset((Long)newValue);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__END_OFFSET:
				setEndOffset((Long)newValue);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__LENGTH:
				setLength((Integer)newValue);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4:
				setNumberOfUnusedBitsAtEndOfSection4((Byte)newValue);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__BINARY_SCALE_FACTOR_E:
				setBinaryScaleFactorE((Short)newValue);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__REFERENCE_VALUE:
				setReferenceValue((Integer)newValue);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__SIZE_OF_PACKED_DATUM:
				setSizeOfPackedDatum((Byte)newValue);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__DATA_OFFSET:
				setDataOffset((Long)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SectionsPackage.BINARY_DATA_SECTION__START_OFFSET:
				setStartOffset(START_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__END_OFFSET:
				setEndOffset(END_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__LENGTH:
				setLength(LENGTH_EDEFAULT);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4:
				setNumberOfUnusedBitsAtEndOfSection4(NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4_EDEFAULT);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__BINARY_SCALE_FACTOR_E:
				setBinaryScaleFactorE(BINARY_SCALE_FACTOR_E_EDEFAULT);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__REFERENCE_VALUE:
				setReferenceValue(REFERENCE_VALUE_EDEFAULT);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__SIZE_OF_PACKED_DATUM:
				setSizeOfPackedDatum(SIZE_OF_PACKED_DATUM_EDEFAULT);
				return;
			case SectionsPackage.BINARY_DATA_SECTION__DATA_OFFSET:
				setDataOffset(DATA_OFFSET_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SectionsPackage.BINARY_DATA_SECTION__START_OFFSET:
				return startOffset != START_OFFSET_EDEFAULT;
			case SectionsPackage.BINARY_DATA_SECTION__END_OFFSET:
				return endOffset != END_OFFSET_EDEFAULT;
			case SectionsPackage.BINARY_DATA_SECTION__LENGTH:
				return length != LENGTH_EDEFAULT;
			case SectionsPackage.BINARY_DATA_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4:
				return numberOfUnusedBitsAtEndOfSection4 != NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION4_EDEFAULT;
			case SectionsPackage.BINARY_DATA_SECTION__BINARY_SCALE_FACTOR_E:
				return binaryScaleFactorE != BINARY_SCALE_FACTOR_E_EDEFAULT;
			case SectionsPackage.BINARY_DATA_SECTION__REFERENCE_VALUE:
				return referenceValue != REFERENCE_VALUE_EDEFAULT;
			case SectionsPackage.BINARY_DATA_SECTION__SIZE_OF_PACKED_DATUM:
				return sizeOfPackedDatum != SIZE_OF_PACKED_DATUM_EDEFAULT;
			case SectionsPackage.BINARY_DATA_SECTION__DATA_OFFSET:
				return dataOffset != DATA_OFFSET_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (startOffset: "); //$NON-NLS-1$
		result.append(startOffset);
		result.append(", endOffset: "); //$NON-NLS-1$
		result.append(endOffset);
		result.append(", length: "); //$NON-NLS-1$
		result.append(length);
		result.append(", numberOfUnusedBitsAtEndOfSection4: "); //$NON-NLS-1$
		result.append(numberOfUnusedBitsAtEndOfSection4);
		result.append(", binaryScaleFactorE: "); //$NON-NLS-1$
		result.append(binaryScaleFactorE);
		result.append(", referenceValue: "); //$NON-NLS-1$
		result.append(referenceValue);
		result.append(", sizeOfPackedDatum: "); //$NON-NLS-1$
		result.append(sizeOfPackedDatum);
		result.append(", dataOffset: "); //$NON-NLS-1$
		result.append(dataOffset);
		result.append(')');
		return result.toString();
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.firstEdition.sections.BinaryDataSection#initialise(java.nio.ByteBuffer)
	 */
	@Override
	public void initialise(ByteBuffer buffer) {
		numberOfUnusedBitsAtEndOfSection4 = buffer.get();
		binaryScaleFactorE = buffer.getShort();
		referenceValue = buffer.getInt();
		sizeOfPackedDatum = buffer.get();
		dataOffset = startOffset + Grib1Constantes.NB_OCTETS_INT_GRIB + buffer.position();
	}
	
} //BinaryDataSectionImpl
